package com.zxc.item.controller;

import com.zxc.common.vo.ResultVo;
import com.zxc.item.entity.TbBrand;
import com.zxc.item.service.TbBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class TbBrandController {

    @Autowired
    private TbBrandService tbBrandService;

    /*
    * 加载品牌列表
    * 1、直接访问服务的地址http://localhost:7000/brand/list
    * 2、通过网关访问服务http://localhost:9000/api/item/brand/list
    * 3、通过域名访问http://api.shopping.com/api/item/brand/list
    * */
    @RequestMapping(value = "/brand/list")
    public ResponseEntity<ResultVo<TbBrand>> getAllBrand(){
        ResultVo<TbBrand> tbBrandResultVo = tbBrandService.getAllBrand();

        return ResponseEntity.ok(tbBrandResultVo);
    }

    @PostMapping(value = "/brand/save")
    public ResponseEntity<Void> save(TbBrand tbBrand){
        System.out.println("进入添加品牌controller==="+tbBrand);
        tbBrandService.save(tbBrand);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

}
